namespace RivercrabNet
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;

    public class PaintLineTriangle : PaintLineBase
    {
        public PaintLineTriangle()
        {
            base.LineType = PaintLineType.Triangle;
            base.PlName_zh = "三角形";
        }

        public override void BeginMove()
        {
            if (base.PointList.Count != 0)
            {
                Point crossHairPoint = base.CgInstance.GetCrossHairPoint();
                base.BeginMovePoint = crossHairPoint;
                base.MoveType = 0;
                ChartDiv local1 = base.CgInstance.DicChartDiv[base.OwnedPanelID];
                PaintLineBase.PointValue value2 = base.PointList[0];
                float num = base.CgInstance.GetY(base.OwnedPanelID, value2.Value, null);
                PaintLineBase.PointValue value3 = base.PointList[1];
                float num2 = base.CgInstance.GetY(base.OwnedPanelID, value3.Value, null);
                PaintLineBase.PointValue value4 = base.PointList[2];
                float num3 = base.CgInstance.GetY(base.OwnedPanelID, value4.Value, null);
                PaintLineBase.PointValue value5 = base.PointList[0];
                int pos = base.CgInstance.GetRecordByTime(value5.Key) - 1;
                PaintLineBase.PointValue value6 = base.PointList[1];
                int num5 = base.CgInstance.GetRecordByTime(value6.Key) - 1;
                PaintLineBase.PointValue value7 = base.PointList[2];
                int num6 = base.CgInstance.GetRecordByTime(value7.Key) - 1;
                float x = base.CgInstance.GetX(pos);
                float num8 = base.CgInstance.GetX(num5);
                float num9 = base.CgInstance.GetX(num6);
                if (((crossHairPoint.X >= (x - (base.LineWidth * 2.5f))) && (crossHairPoint.X <= (x + (base.LineWidth * 2.5f)))) && ((crossHairPoint.Y >= (num - (base.LineWidth * 2.5f))) && (crossHairPoint.Y <= (num + (base.LineWidth * 2.5f)))))
                {
                    base.CgInstance.Cursor = Cursors.SizeWE;
                    base.MoveType = 1;
                }
                else if (((crossHairPoint.X >= (num8 - (base.LineWidth * 2.5f))) && (crossHairPoint.X <= (num8 + (base.LineWidth * 2.5f)))) && ((crossHairPoint.Y >= (num2 - (base.LineWidth * 2.5f))) && (crossHairPoint.Y <= (num2 + (base.LineWidth * 2.5f)))))
                {
                    base.CgInstance.Cursor = Cursors.SizeWE;
                    base.MoveType = 2;
                }
                else if (((crossHairPoint.X >= (num9 - (base.LineWidth * 2.5f))) && (crossHairPoint.X <= (num9 + (base.LineWidth * 2.5f)))) && ((crossHairPoint.Y >= (num3 - (base.LineWidth * 2.5f))) && (crossHairPoint.Y <= (num3 + (base.LineWidth * 2.5f)))))
                {
                    base.CgInstance.Cursor = Cursors.SizeWE;
                    base.MoveType = 3;
                }
                else
                {
                    base.CgInstance.Cursor = Cursors.Hand;
                    base.MoveType = 0;
                }
                base.BeginMoveValue.Clear();
                base.BeginMoveValue.Add(base.PointList[0]);
                base.BeginMoveValue.Add(base.PointList[1]);
                base.BeginMoveValue.Add(base.PointList[2]);
            }
        }

        public override void Draw(Graphics g, List<PaintLineBase.PointValue> pList, Color curColor)
        {
            if (pList.Count != 0)
            {
                ChartDiv div = base.CgInstance.DicChartDiv[base.OwnedPanelID];
                PaintLineBase.PointValue value2 = pList[0];
                float num = (base.CgInstance.GetY(base.OwnedPanelID, value2.Value, null) - div.Rect.Y) - div.TitleHeight;
                PaintLineBase.PointValue value3 = pList[1];
                float num2 = (base.CgInstance.GetY(base.OwnedPanelID, value3.Value, null) - div.Rect.Y) - div.TitleHeight;
                PaintLineBase.PointValue value4 = pList[2];
                float num3 = (base.CgInstance.GetY(base.OwnedPanelID, value4.Value, null) - div.Rect.Y) - div.TitleHeight;
                PaintLineBase.PointValue value5 = pList[0];
                int pos = base.CgInstance.GetRecordByTime(value5.Key) - 1;
                PaintLineBase.PointValue value6 = pList[1];
                int num5 = base.CgInstance.GetRecordByTime(value6.Key) - 1;
                PaintLineBase.PointValue value7 = pList[2];
                int num6 = base.CgInstance.GetRecordByTime(value7.Key) - 1;
                float num7 = base.CgInstance.GetX(pos) - base.CgInstance.LeftYScaleWidth;
                float num8 = base.CgInstance.GetX(num5) - base.CgInstance.LeftYScaleWidth;
                float num9 = base.CgInstance.GetX(num6) - base.CgInstance.LeftYScaleWidth;
                Brush brush = new SolidBrush(curColor);
                Pen pen = new Pen(brush) {
                    Width = (float) base.LineWidth
                };
                if (base.LineStyle != null)
                {
                    pen.DashPattern = base.LineStyle;
                }
                g.DrawLine(pen, num7, num, num8, num2);
                g.DrawLine(pen, num7, num, num9, num3);
                g.DrawLine(pen, num8, num2, num9, num3);
                if (base.Selected || (((num7 == num8) && (num8 == num9)) && ((num == num2) && (num2 == num3))))
                {
                    g.FillRectangle(brush, new RectangleF(num7 - (base.LineWidth * 2.5f), num - (base.LineWidth * 2.5f), (float) (base.LineWidth * 5), (float) (base.LineWidth * 5)));
                    g.FillRectangle(brush, new RectangleF(num8 - (base.LineWidth * 2.5f), num2 - (base.LineWidth * 2.5f), (float) (base.LineWidth * 5), (float) (base.LineWidth * 5)));
                    g.FillRectangle(brush, new RectangleF(num9 - (base.LineWidth * 2.5f), num3 - (base.LineWidth * 2.5f), (float) (base.LineWidth * 5), (float) (base.LineWidth * 5)));
                }
                pen.Dispose();
                brush.Dispose();
            }
        }

        public override bool Init(Point mp)
        {
            if (base.CgInstance.DataSource.Rows.Count > 0)
            {
                int indexByPoint = base.CgInstance.GetIndexByPoint(mp);
                double valueByPoint = base.CgInstance.GetValueByPoint(mp);
                string key = base.CgInstance.DataSource.Rows[indexByPoint][base.CgInstance.CalenderScaleField].ToString();
                base.PointList.Clear();
                base.PointList.Add(new PaintLineBase.PointValue(0, key, valueByPoint));
                base.PointList.Add(new PaintLineBase.PointValue(1, key, valueByPoint));
                base.PointList.Add(new PaintLineBase.PointValue(2, key, valueByPoint));
                return true;
            }
            return false;
        }

        public override bool JudgeSelect()
        {
            if (base.PointList.Count != 0)
            {
                ChartDiv local1 = base.CgInstance.DicChartDiv[base.OwnedPanelID];
                PaintLineBase.PointValue value2 = base.PointList[0];
                float num = base.CgInstance.GetY(base.OwnedPanelID, value2.Value, null);
                PaintLineBase.PointValue value3 = base.PointList[1];
                float num2 = base.CgInstance.GetY(base.OwnedPanelID, value3.Value, null);
                PaintLineBase.PointValue value4 = base.PointList[2];
                float num3 = base.CgInstance.GetY(base.OwnedPanelID, value4.Value, null);
                PaintLineBase.PointValue value5 = base.PointList[0];
                int pos = base.CgInstance.GetRecordByTime(value5.Key) - 1;
                PaintLineBase.PointValue value6 = base.PointList[1];
                int num5 = base.CgInstance.GetRecordByTime(value6.Key) - 1;
                PaintLineBase.PointValue value7 = base.PointList[2];
                int num6 = base.CgInstance.GetRecordByTime(value7.Key) - 1;
                float x = base.CgInstance.GetX(pos);
                float num8 = base.CgInstance.GetX(num5);
                float num9 = base.CgInstance.GetX(num6);
                Point crossHairPoint = base.CgInstance.GetCrossHairPoint();
                if (((crossHairPoint.X >= (x - (base.LineWidth * 2.5f))) && (crossHairPoint.X <= (x + (base.LineWidth * 2.5f)))) && ((crossHairPoint.Y >= (num - (base.LineWidth * 2.5f))) && (crossHairPoint.Y <= (num + (base.LineWidth * 2.5f)))))
                {
                    return true;
                }
                if (((crossHairPoint.X >= (num8 - (base.LineWidth * 2.5f))) && (crossHairPoint.X <= (num8 + (base.LineWidth * 2.5f)))) && ((crossHairPoint.Y >= (num2 - (base.LineWidth * 2.5f))) && (crossHairPoint.Y <= (num2 + (base.LineWidth * 2.5f)))))
                {
                    return true;
                }
                if (((crossHairPoint.X >= (num9 - (base.LineWidth * 2.5f))) && (crossHairPoint.X <= (num9 + (base.LineWidth * 2.5f)))) && ((crossHairPoint.Y >= (num3 - (base.LineWidth * 2.5f))) && (crossHairPoint.Y <= (num3 + (base.LineWidth * 2.5f)))))
                {
                    return true;
                }
                double[] numArray = Common.GetLineParam(x, num, num8, num2);
                float num10 = (x <= num8) ? x : num8;
                float num11 = (num <= num2) ? num : num2;
                float num12 = (x > num8) ? x : num8;
                float num13 = (num > num2) ? num : num2;
                if (((crossHairPoint.X >= (num10 - 2f)) && (crossHairPoint.X <= (num12 + 2f))) && ((crossHairPoint.Y >= (num11 - 2f)) && (crossHairPoint.Y <= (num13 + 2f))))
                {
                    if (numArray == null)
                    {
                        return true;
                    }
                    if (((((double) crossHairPoint.Y) / ((crossHairPoint.X * numArray[0]) + numArray[1])) >= 0.95) && ((((double) crossHairPoint.Y) / ((crossHairPoint.X * numArray[0]) + numArray[1])) <= 1.05))
                    {
                        return true;
                    }
                }
                if (((numArray != null) && (crossHairPoint.X >= (num10 - (base.LineWidth * 2.5f)))) && ((crossHairPoint.X <= (num12 + (base.LineWidth * 2.5f))) && (crossHairPoint.Y >= (num11 - (base.LineWidth * 2.5f)))))
                {
                    float single1 = num13 + (base.LineWidth * 2.5f);
                    float y = crossHairPoint.Y;
                }
                numArray = Common.GetLineParam(x, num, num9, num3);
                num10 = (x <= num9) ? x : num9;
                num11 = (num <= num3) ? num : num3;
                num12 = (x > num9) ? x : num9;
                num13 = (num > num3) ? num : num3;
                if (((crossHairPoint.X >= (num10 - (base.LineWidth * 2.5f))) && (crossHairPoint.X <= (num12 + (base.LineWidth * 2.5f)))) && ((crossHairPoint.Y >= (num11 - (base.LineWidth * 2.5f))) && (crossHairPoint.Y <= (num13 + (base.LineWidth * 2.5f)))))
                {
                    if (numArray == null)
                    {
                        return true;
                    }
                    if (((((double) crossHairPoint.Y) / ((crossHairPoint.X * numArray[0]) + numArray[1])) >= 0.95) && ((((double) crossHairPoint.Y) / ((crossHairPoint.X * numArray[0]) + numArray[1])) <= 1.05))
                    {
                        return true;
                    }
                }
                numArray = Common.GetLineParam(num8, num2, num9, num3);
                num10 = (num8 <= num9) ? num8 : num9;
                num11 = (num2 <= num3) ? num2 : num3;
                num12 = (num8 > num9) ? num8 : num9;
                num13 = (num2 > num3) ? num2 : num3;
                if (((crossHairPoint.X >= (num10 - (base.LineWidth * 2.5f))) && (crossHairPoint.X <= (num12 + (base.LineWidth * 2.5f)))) && ((crossHairPoint.Y >= (num11 - (base.LineWidth * 2.5f))) && (crossHairPoint.Y <= (num13 + (base.LineWidth * 2.5f)))))
                {
                    if (numArray == null)
                    {
                        return true;
                    }
                    if (((((double) crossHairPoint.Y) / ((crossHairPoint.X * numArray[0]) + numArray[1])) >= 0.95) && ((((double) crossHairPoint.Y) / ((crossHairPoint.X * numArray[0]) + numArray[1])) <= 1.05))
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public override double[] LineParam()
        {
            return null;
        }

        public override void Move()
        {
            if (base.PointList.Count != 0)
            {
                Point crossHairPoint = base.CgInstance.GetCrossHairPoint();
                ChartDiv div = base.CgInstance.DicChartDiv[base.OwnedPanelID];
                if ((crossHairPoint.Y >= (div.Rect.Y + div.TitleHeight)) && (crossHairPoint.Y <= (div.Rect.Bottom - div.CalenderScale.Height)))
                {
                    int mouseOverIndex = base.CgInstance.GetMouseOverIndex();
                    double mouseOverValue = base.CgInstance.GetMouseOverValue();
                    if (mouseOverIndex < 0)
                    {
                        mouseOverIndex = 0;
                    }
                    if (mouseOverIndex > (base.CgInstance.LastVisibleRecord - 1))
                    {
                        mouseOverIndex = base.CgInstance.LastVisibleRecord - 1;
                    }
                    switch (base.MoveType)
                    {
                        case 0:
                        {
                            double num3 = crossHairPoint.Y - base.BeginMovePoint.Y;
                            double num4 = base.CgInstance.DicChartDiv[base.OwnedPanelID].MaxValue[0];
                            double num5 = base.CgInstance.DicChartDiv[base.OwnedPanelID].MinValue[0];
                            double num6 = (num3 / ((double) base.CgInstance.GetWorkSpaceY(base.OwnedPanelID))) * (num5 - num4);
                            int indexByPoint = base.CgInstance.GetIndexByPoint(base.BeginMovePoint);
                            int num8 = base.CgInstance.GetIndexByPoint(crossHairPoint);
                            PaintLineBase.PointValue value2 = base.BeginMoveValue[0];
                            int num9 = (base.CgInstance.GetRecordByTime(value2.Key) + (num8 - indexByPoint)) - 1;
                            PaintLineBase.PointValue value3 = base.BeginMoveValue[1];
                            int num10 = (base.CgInstance.GetRecordByTime(value3.Key) + (num8 - indexByPoint)) - 1;
                            PaintLineBase.PointValue value4 = base.BeginMoveValue[2];
                            int num11 = (base.CgInstance.GetRecordByTime(value4.Key) + (num8 - indexByPoint)) - 1;
                            if (num9 >= 0)
                            {
                                if (num9 > (base.CgInstance.DataSource.Rows.Count - 1))
                                {
                                    num9 = base.CgInstance.DataSource.Rows.Count - 1;
                                }
                            }
                            else
                            {
                                num9 = 0;
                            }
                            if (num10 < 0)
                            {
                                num10 = 0;
                            }
                            else if (num10 > (base.CgInstance.DataSource.Rows.Count - 1))
                            {
                                num10 = base.CgInstance.DataSource.Rows.Count - 1;
                            }
                            if (num11 < 0)
                            {
                                num11 = 0;
                            }
                            else if (num11 > (base.CgInstance.DataSource.Rows.Count - 1))
                            {
                                num11 = base.CgInstance.DataSource.Rows.Count - 1;
                            }
                            PaintLineBase.PointValue value5 = base.BeginMoveValue[0];
                            base.PointList[0] = new PaintLineBase.PointValue(0, base.CgInstance.DataSource.Rows[num9][base.CgInstance.CalenderScaleField].ToString(), value5.Value + num6);
                            PaintLineBase.PointValue value6 = base.BeginMoveValue[1];
                            base.PointList[1] = new PaintLineBase.PointValue(1, base.CgInstance.DataSource.Rows[num10][base.CgInstance.CalenderScaleField].ToString(), value6.Value + num6);
                            PaintLineBase.PointValue value7 = base.BeginMoveValue[2];
                            base.PointList[2] = new PaintLineBase.PointValue(2, base.CgInstance.DataSource.Rows[num11][base.CgInstance.CalenderScaleField].ToString(), value7.Value + num6);
                            return;
                        }
                        case 1:
                            base.PointList[0] = new PaintLineBase.PointValue(0, base.CgInstance.DataSource.Rows[mouseOverIndex][base.CgInstance.CalenderScaleField].ToString(), mouseOverValue);
                            return;

                        case 2:
                            base.PointList[1] = new PaintLineBase.PointValue(1, base.CgInstance.DataSource.Rows[mouseOverIndex][base.CgInstance.CalenderScaleField].ToString(), mouseOverValue);
                            return;

                        case 3:
                            base.PointList[2] = new PaintLineBase.PointValue(2, base.CgInstance.DataSource.Rows[mouseOverIndex][base.CgInstance.CalenderScaleField].ToString(), mouseOverValue);
                            return;
                    }
                }
            }
        }
    }
}

